#region File Description
//-----------------------------------------------------------------------------
// Player.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
#endregion

namespace MilwormsGameData
{
    /// <summary>
    /// A member of the player's party, also represented in the world before joining.
    /// </summary>
    /// <remarks>
    /// There is only one of a given Player in the game world at a time, and their 
    /// current statistics persist after combat.  Thererefore, current statistics 
    /// are tracked here.
    /// </remarks>
    public class Player : FightingCharacter
    {

        #region Dialogue Data


        /// <summary>
        /// The dialogue that the player says when it is greeted as an Npc in the world.
        /// </summary>
        private string introductionDialogue;

        /// <summary>
        /// The dialogue that the player says when it is greeted as an Npc in the world.
        /// </summary>
        public string IntroductionDialogue
        {
            get { return introductionDialogue; }
            set { introductionDialogue = value; }
        }


        /// <summary>
        /// The dialogue that the player says when its offer to join is accepted.
        /// </summary>
        private string joinAcceptedDialogue;

        /// <summary>
        /// The dialogue that the player says when its offer to join is accepted.
        /// </summary>
        public string JoinAcceptedDialogue
        {
            get { return joinAcceptedDialogue; }
            set { joinAcceptedDialogue = value; }
        }


        /// <summary>
        /// The dialogue that the player says when its offer to join is rejected.
        /// </summary>
        private string joinRejectedDialogue;

        /// <summary>
        /// The dialogue that the player says when its offer to join is rejected.
        /// </summary>
        public string JoinRejectedDialogue
        {
            get { return joinRejectedDialogue; }
            set { joinRejectedDialogue = value; }
        }


        #endregion


        #region Portrait Data

        /// <summary>
        /// The name of the active portrait texture.
        /// </summary>
        protected string activePortraitTextureName;

        /// <summary>
        /// The name of the active portrait texture.
        /// </summary>
        public string ActivePortraitTextureName
        {
            get { return activePortraitTextureName; }
            set { activePortraitTextureName = value; }
        }


        /// <summary>
        /// The active portrait texture.
        /// </summary>
        protected Texture2D activePortraitTexture;

        /// <summary>
        /// The active portrait texture.
        /// </summary>
        [ContentSerializerIgnore]
        public Texture2D ActivePortraitTexture
        {
            get { return activePortraitTexture; }
        }

        #endregion


        #region Content Type Reader


        /// <summary>
        /// Read a Player object from the content pipeline.
        /// </summary>
        public class PlayerReader : ContentTypeReader<Player>
        {

            protected override Player Read(ContentReader input, Player existingInstance)
            {
                Player player = existingInstance;
                if (player == null)
                {
                    player = new Player();
                }


                input.ReadRawObject<FightingCharacter>(player as FightingCharacter);

                player.IntroductionDialogue = input.ReadString();
                player.JoinAcceptedDialogue = input.ReadString();
                player.JoinRejectedDialogue = input.ReadString();
                player.ActivePortraitTextureName = input.ReadString();
                player.activePortraitTexture =
                    input.ContentManager.Load<Texture2D>(
                        System.IO.Path.Combine(@"Textures\Characters\Portraits",
                        player.ActivePortraitTextureName));

                return player;
            }
        }


        #endregion


        #region ICloneable Members


        public object Clone()
        {
            Player player = new Player();

            player.activePortraitTexture = activePortraitTexture;
            player.activePortraitTextureName = activePortraitTextureName;
            player.AssetName = AssetName;
            player.CharacterClass = CharacterClass;
            player.CharacterClassContentName = CharacterClassContentName;
            player.CharacterLevel = CharacterLevel;
            player.Direction = Direction;
            player.EquippedEquipment.AddRange(EquippedEquipment);
            player.Experience = Experience;
            player.InitialEquipmentContentNames.AddRange(InitialEquipmentContentNames);
            player.introductionDialogue = introductionDialogue;
            player.Inventory.AddRange(Inventory);
            player.joinAcceptedDialogue = joinAcceptedDialogue;
            player.joinRejectedDialogue = joinRejectedDialogue;
            player.MapIdleAnimationInterval = MapIdleAnimationInterval;
            player.MapPosition = MapPosition;
            player.MapSprite = MapSprite.Clone() as AnimatingSprite;
            player.MapWalkingAnimationInterval = MapWalkingAnimationInterval;
            player.Name = Name;
            player.ShadowTexture = ShadowTexture;
            player.State = State;
            player.WalkingSprite = WalkingSprite.Clone() as AnimatingSprite;

            player.ResetAnimation(false);

            return player;
        }


        #endregion

    }

}

